#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include <stdlib.h> 
#include <string.h> 
#include "gestion.h"
#include "bilan.h"

void
on_button1_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{char password[15];
char login[15];
char pswrd[15]="0000";
char log[15]="admin";

int x,y;

GtkWidget *entry68;
GtkWidget *entry69;


GtkWidget *window2;
entry68 = lookup_widget(objet_graphique, "entry68");
entry69 = lookup_widget(objet_graphique, "entry69");

strcpy(login, gtk_entry_get_text(GTK_ENTRY(entry68)));
strcpy(password, gtk_entry_get_text(GTK_ENTRY(entry69)));
x=strcmp(log,login);
y=strcmp(pswrd,password);

if ((x==0) && (y==0))
{window2 = create_window2();
gtk_widget_show(window2);


}
else
{ char ch[100];

GtkWidget * label119;

	label119= lookup_widget(objet_graphique, "label119");
strcpy(ch,"password et login erroné");	
gtk_label_set_text(GTK_LABEL(label119),ch);
}
}

void
on_button2_clicked                  (GtkWidget *objet_graphique, gpointer user_data)
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window4;
window4 = create_window4();
    gtk_widget_show(window4);

}





void
on_button3_clicked            (GtkWidget *objet_graphique, gpointer user_data)      
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window6;
window6 = create_window6();
    gtk_widget_show(window6);
}


void
on_button4_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window8;
window8 = create_window8();
    gtk_widget_show(window8);

}


void
on_button5_clicked                     (GtkWidget *objet_graphique, gpointer user_data)
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window9;
window9 = create_window9();
    gtk_widget_show(window9);
GtkWidget *label90;

struct patient p;
	char fichier[] = "patients.txt";
	
	char tmp[100000]="";
	char Buf[10000]="";
	char Buf0[100]= " ID ";
	char Buf1[100]= " nom ";
	char Buf2[100]= " prenom ";
	char Buf3[100]= " age ";
	char Buf4[100]= " observation ";
	char Buf5[100]= " sexe ";
	char Buf6[100]= " adresse ";
	char Buf7[100]= " Type du sang ";
	char Buf8[100]= " pays ";
	char Buf9[100]= " Nationnalitée ";
	char Buf10[100]= " Telephone ";
	char Buf11[100]= " Numero accompagnant ";
	FILE*f;

f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, "%d %s %s %d %s %s %s %s %s %s %d %d ", &p.iden,p.nom, p.prenom,&p.age,p.observation, p.sexe,p.adresse,p.tsang,p.pays,p.nationnalite,&p.tel,&p.numacc) != EOF )
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.observation, Buf5, p.sexe, Buf6,p.adresse, Buf7,p.tsang, Buf8,p.pays, Buf9,p.nationnalite, Buf10,p.tel,Buf11,p.numacc  );
 strcat(tmp,Buf);
strcat(tmp,"\n\n");
 } 
  	
label90= lookup_widget(GTK_WIDGET(window9), "label90");
   gtk_label_set_text(GTK_LABEL(label90),tmp);
  }else {label90= lookup_widget(GTK_WIDGET(window9), "label90");
   gtk_label_set_text(GTK_LABEL(label90),"clinique vide");}
  
fclose(f); }


void
on_button11_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window2;
window2 = create_window2();
    gtk_widget_show(window2);

}


void
on_button10_clicked                  (GtkWidget *objet_graphique, gpointer user_data) 
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window9;
window9 = create_window9();
    gtk_widget_show(window9);


}


void
on_button9_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window9;
window9 = create_window9();
    gtk_widget_show(window9);

}


void
on_button8_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window9;
window9 = create_window9();
    gtk_widget_show(window9);

}


void
on_button7_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window9;
window9 = create_window9();
    gtk_widget_show(window9);

}


void
on_button6_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{		GtkWidget * window3;
		window3 = lookup_widget(objet_graphique,"window3");
		gtk_widget_hide(window3);
GtkWidget *window9;
window9 = create_window9();
    gtk_widget_show(window9);

}



void
on_button13_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window3;
window3 = create_window3();
    gtk_widget_show(window3);


}

int sexe=1;
void
on_button12_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{

int x;
        struct patient Pa;
	char chemin[20] = "patients.txt";
        

	GtkWidget *entry19;
	GtkWidget *entry20;
	GtkWidget *entry21;
	GtkWidget *entry23;
        GtkWidget *entry22;
        GtkWidget *entry25;
	GtkWidget *entry26;
        GtkWidget *entry28;
	GtkWidget *entry29;
	GtkWidget *entry30;
	GtkWidget *entry80;

        
	
	entry19 = lookup_widget(objet_graphique, "entry19");
	entry20 = lookup_widget(objet_graphique, "entry20");
	entry21 = lookup_widget(objet_graphique, "entry21");
        entry22 = lookup_widget(objet_graphique, "entry22");
	entry23 = lookup_widget(objet_graphique, "entry23");
        entry25 = lookup_widget(objet_graphique, "entry25");
	entry26 = lookup_widget(objet_graphique, "entry26");   
	entry28 = lookup_widget(objet_graphique, "entry28");
	entry29 = lookup_widget(objet_graphique, "entry29");
        entry30 = lookup_widget(objet_graphique, "entry30");
	entry80 = lookup_widget(objet_graphique, "entry80");


	Pa.iden = atoi(gtk_entry_get_text(GTK_ENTRY(entry19)));
	strcpy(Pa.nom, gtk_entry_get_text(GTK_ENTRY(entry20)));
	strcpy(Pa.prenom, gtk_entry_get_text(GTK_ENTRY(entry21)));
	strcpy(Pa.pays, gtk_entry_get_text(GTK_ENTRY(entry29)));
	strcpy(Pa.adresse, gtk_entry_get_text(GTK_ENTRY(entry25)));
	Pa.tel=atoi(gtk_entry_get_text(GTK_ENTRY(entry26)));
	strcpy(Pa.tsang, gtk_entry_get_text(GTK_ENTRY(entry28)));
	Pa.age=atoi(gtk_entry_get_text(GTK_ENTRY(entry22)));
	strcpy(Pa.nationnalite,gtk_entry_get_text(GTK_ENTRY(entry30)));
	Pa.numacc=atoi(gtk_entry_get_text(GTK_ENTRY(entry80)));
        strcpy(Pa.observation,gtk_entry_get_text(GTK_ENTRY(entry23)));
        if(sexe == 1)
		strcpy(Pa.sexe,"HOMME");
	else
		strcpy(Pa.sexe,"FEMME");

    x=sauvegarder_patient(chemin,Pa);

	GtkWidget * window4;
        window4 = lookup_widget(objet_graphique,"window4");
        gtk_widget_hide(window4);
GtkWidget *window5;
window5 = create_window5();
 gtk_widget_show(window5);
	GtkWidget *label110;

struct patient p;
	char fichier[] = "patients.txt";
	
	char tmp[100000]="";
	char Buf[10000]="";
	char Buf0[100]= " ID ";
	char Buf1[100]= " nom ";
	char Buf2[100]= " prenom ";
	char Buf3[100]= " age ";
	char Buf4[100]= " observation ";
	char Buf5[100]= " sexe ";
	char Buf6[100]= " adresse ";
	char Buf7[100]= " Type du sang ";
	char Buf8[100]= " pays ";
	char Buf9[100]= " Nationnalitée ";
	char Buf10[100]= " Telephone ";
	char Buf11[100]= " Numero accompagnant ";
	FILE*f;

f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, "%d %s %s %d %s %s %s %s %s %s %d %d \n", &p.iden,p.nom, p.prenom,&p.age,p.observation, p.sexe,p.adresse,p.tsang,p.pays,p.nationnalite,&p.tel,&p.numacc) != EOF )
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.observation, Buf5, p.sexe, Buf6,p.adresse, Buf7,p.tsang, Buf8,p.pays, Buf9,p.nationnalite, Buf10,p.tel,Buf11,p.numacc  );
 strcat(tmp,Buf);
strcat(tmp,"\n\n");
 }
  	
label110= lookup_widget(GTK_WIDGET(window5), "label110");
   gtk_label_set_text(GTK_LABEL(label110),tmp);
  }else {label110= lookup_widget(GTK_WIDGET(window5), "label110");
   gtk_label_set_text(GTK_LABEL(label110),"clinique vide");}
  
fclose(f); 
	
}


void
on_button14_clicked                     (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget * window5;
        window5 = lookup_widget(objet_graphique,"window5");
        gtk_widget_hide(window5);
GtkWidget *window3;
window3 = create_window3();
    gtk_widget_show(window3);

}


void
on_button16_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window3;
window3 = create_window3();
    gtk_widget_show(window3);

}


void
on_button15_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window7;	
        int test;
	struct patient p;
		struct patient pa;
	char fichier[] = "patients.txt";
	char Buf[200]="";
	char Buf0[30]= " ID ";
	char Buf1[30]= " nom ";
	char Buf2[30]= " prenom ";
	char Buf3[30]= " age ";
	char Buf4[30]= " observation ";
	char Buf5[30]= " sexe ";
	char Buf6[30]= " adresse ";
	char Buf7[30]= " Type du sang ";
	char Buf8[30]= " pays ";
	char Buf9[30]= " Nationnalitée ";
	char Buf10[30]= " Telephone ";
	char Buf11[30]= " Numero accompagnant ";
	char Buf12[30];
	GtkWidget *entry32;
	GtkWidget *entry33;
	GtkWidget *entry34;
	GtkWidget *entry35;
	GtkWidget *entry36;
	GtkWidget *entry37;
	GtkWidget *entry81;
	GtkWidget *entry82;
	GtkWidget *entry83;
	GtkWidget *entry84;
	GtkWidget *entry85;
	GtkWidget *entry86;
	
	GtkWidget *entry38;
	GtkWidget * label85;
	GtkWidget * label118;
entry38 = lookup_widget(objet_graphique, "entry38");
pa.iden = atoi(gtk_entry_get_text(GTK_ENTRY(entry38)));
test=chercherpatient(fichier,pa.iden);	
if (test==1)
{
window7 = create_window7();
    gtk_widget_show(window7);
	FILE*f;
f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, "%d %s %s %d %s %s %s %s %s %s %d %d ", &p.iden,p.nom, p.prenom,&p.age,p.observation, p.sexe,p.adresse,p.tsang,p.pays,p.nationnalite,&p.tel,&p.numacc) != EOF )
  {    if (pa.iden==p.iden){
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.observation, Buf5, p.sexe, Buf6,p.adresse, Buf7,p.tsang, Buf8,p.pays, Buf9,p.nationnalite, Buf10,p.tel,Buf11,p.numacc  );}}fclose(f);
label118= lookup_widget(GTK_WIDGET(window7), "label118");
   gtk_label_set_text(GTK_LABEL(label118),Buf);;
}} else  
 {
sprintf(Buf12,"Personnel innexistant \n");
label85= lookup_widget(objet_graphique, "label85"); 
gtk_label_set_text(GTK_LABEL(label85), Buf12);}

}


void
on_button17_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{int x;
char fichier[]="patients.txt";
struct patient p;
struct patient pa;
        char Buf[1000]="";
	char Buf0[30]= " ID ";
	char Buf1[30]= " nom ";
	char Buf2[30]= " prenom ";
	char Buf3[30]= " age ";
	char Buf4[30]= " observation ";
	char Buf5[30]= " sexe ";
	char Buf6[30]= " adresse ";
	char Buf7[30]= " Type du sang ";
	char Buf8[30]= " pays ";
	char Buf9[30]= " Nationnalitée ";
	char Buf10[30]= " Telephone ";
	char Buf11[30]= " Numero accompagnant ";	
 	GtkWidget *window7;
	GtkWidget *label118; 	
 	GtkWidget *entry32;
	GtkWidget *entry33;
	GtkWidget *entry34;
	GtkWidget *entry35;
	GtkWidget *entry36;
	GtkWidget *entry37;
	GtkWidget *entry81;
	GtkWidget *entry82;
	GtkWidget *entry83;
	GtkWidget *entry84;
	GtkWidget *entry85;
	GtkWidget *entry86;
        entry32 = lookup_widget(objet_graphique, "entry32");
	entry33 = lookup_widget(objet_graphique, "entry33");
	entry34 = lookup_widget(objet_graphique, "entry34");
	entry35 = lookup_widget(objet_graphique, "entry35");
	entry36 = lookup_widget(objet_graphique, "entry36");
	entry37 = lookup_widget(objet_graphique, "entry37");
	entry81 = lookup_widget(objet_graphique, "entry81");
	entry82 = lookup_widget(objet_graphique, "entry82");
	entry84 = lookup_widget(objet_graphique, "entry84");
	entry83 = lookup_widget(objet_graphique, "entry83");
	entry85 = lookup_widget(objet_graphique, "entry85");
	entry86 = lookup_widget(objet_graphique, "entry86");
	pa.iden = atoi(gtk_entry_get_text(GTK_ENTRY(entry32)));
	strcpy(pa.nom, gtk_entry_get_text(GTK_ENTRY(entry33)));
	strcpy(pa.prenom, gtk_entry_get_text(GTK_ENTRY(entry34)));
	strcpy(pa.pays, gtk_entry_get_text(GTK_ENTRY(entry83)));
	strcpy(pa.adresse, gtk_entry_get_text(GTK_ENTRY(entry81)));
	pa.tel=atoi(gtk_entry_get_text(GTK_ENTRY(entry85)));
	strcpy(pa.tsang, gtk_entry_get_text(GTK_ENTRY(entry82)));
	strcpy(pa.sexe, gtk_entry_get_text(GTK_ENTRY(entry37)));
	pa.age=atoi(gtk_entry_get_text(GTK_ENTRY(entry36)));
	strcpy(pa.nationnalite,gtk_entry_get_text(GTK_ENTRY(entry84)));
	pa.numacc=atoi(gtk_entry_get_text(GTK_ENTRY(entry86)));
        strcpy(pa.observation,gtk_entry_get_text(GTK_ENTRY(entry35)));
    supprimer_patient(fichier,pa.iden);
x=sauvegarder_patient(fichier,pa);
	FILE*f;
f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, "%d %s %s %d %s %s %s %s %s %s %d %d ", &p.iden,p.nom, p.prenom,&p.age,p.observation, p.sexe,p.adresse,p.tsang,p.pays,p.nationnalite,&p.tel,&p.numacc) != EOF )
  {    if (pa.iden==p.iden){
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.observation, Buf5, p.sexe, Buf6,p.adresse, Buf7,p.tsang, Buf8,p.pays, Buf9,p.nationnalite, Buf10,p.tel,Buf11,p.numacc  );}}}fclose(f);
label118= lookup_widget(GTK_WIDGET(window7), "label118");
   gtk_label_set_text(GTK_LABEL(label118),Buf);
/*GtkWidget *window6;
window6 = create_window6();
    gtk_widget_show(window6);*/

}


void
on_button29_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window15;
window15 = create_window15();
    gtk_widget_show(window15);
}


void
on_button28_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window15;
window15 = create_window15();
    gtk_widget_show(window15);
}


void
on_button27_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window15;
window15 = create_window15();
    gtk_widget_show(window15);

}


void
on_button26_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window15;
window15 = create_window15();
    gtk_widget_show(window15);
}


void
on_button25_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window15;
window15 = create_window15();
    gtk_widget_show(window15);

}


void
on_button24_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window15;
window15 = create_window15();
    gtk_widget_show(window15);
}

void
on_button23_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window15;
window15 = create_window15();
    gtk_widget_show(window15);
}


void
on_button22_clicked                  (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window14;
window14 = create_window14();
    gtk_widget_show(window14);

}


void
on_button21_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window12;
window12 = create_window12();
    gtk_widget_show(window12);


}


void
on_button20_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window11;
window11 = create_window11();
    gtk_widget_show(window11);


}



void
on_button30_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window2;
window2 = create_window2();
    gtk_widget_show(window2);

}


void
on_button31_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
	int x;/* la variables ds laquelle on a stocke le retour de la fct sauvegarder*/
        struct personnel P;
	char chemin[20] = "personnels.txt";
        

	GtkWidget *entry45;
	GtkWidget *entry46;
	GtkWidget *entry47;
        GtkWidget *entry48;
	GtkWidget *entry49;
	GtkWidget *entry50;
        GtkWidget *entry51;
	GtkWidget *entry52;
        GtkWidget *entry54;
        GtkWidget *entry55;	
	GtkWidget *entry56;


	GtkWidget *window11;
        GtkWidget *window5;

	entry45 = lookup_widget(objet_graphique, "entry45");
	entry46 = lookup_widget(objet_graphique, "entry46");
	entry47 = lookup_widget(objet_graphique, "entry47");
        entry48 = lookup_widget(objet_graphique, "entry48");
	entry49 = lookup_widget(objet_graphique, "entry49");
        entry51 = lookup_widget(objet_graphique, "entry51");
	entry52 = lookup_widget(objet_graphique, "entry52");   
	entry54 = lookup_widget(objet_graphique, "entry54");
	entry55 = lookup_widget(objet_graphique, "entry55");
        entry56 = lookup_widget(objet_graphique, "entry56");

         
         //convertir la chaine saisie à partir de entry19 et la copier dans Pa.identifant
	P.iden = atoi(gtk_entry_get_text(GTK_ENTRY(entry45)));
	//copier la chaine saisie à partir de entry20 vers Pa.nom
	strcpy(P.nom, gtk_entry_get_text(GTK_ENTRY(entry46)));
	//copier la chaine saisie à partir de entry21 vers Pa.prenom
	strcpy(P.prenom, gtk_entry_get_text(GTK_ENTRY(entry47)));
	
        //copier la chaine saisie à partir de entry 22 vers Pa.pays
	strcpy(P.pays, gtk_entry_get_text(GTK_ENTRY(entry48)));
	//copier la chaine saisie à partir de entry23 vers Pa.profession
	strcpy(P.profession, gtk_entry_get_text(GTK_ENTRY(entry49)));
	
	//copier la chaine saisie à partir de entry25 vers Pa.adresse
	strcpy(P.adresse, gtk_entry_get_text(GTK_ENTRY(entry51)));
	//convertir la chaine saisie à partir de entry26 et la copier dans Pa.num de telephone
	P.tel=atoi(gtk_entry_get_text(GTK_ENTRY(entry52)));
	//copier la chaine saisie à partir de entry28 vers Pa.type du sang
	strcpy(P.tsang, gtk_entry_get_text(GTK_ENTRY(entry54)));
        //convertir la chaine saisie à partir de entry29 et la copier dans Pa.age
	P.age=atoi(gtk_entry_get_text(GTK_ENTRY(entry55)));
       //copier la chaine saisie à partir de entry 30 vers Pa.nationnalité
	strcpy(P.nationnalite,gtk_entry_get_text(GTK_ENTRY(entry56)));
	if(sexe == 1)
		strcpy(P.sexe,"HOMME");
	else
		strcpy(P.sexe,"FEMME");
        
    x=sauvegarder_personnel(chemin,P);
//creation et affichage de la deuxième fenetre graphique
	window11= lookup_widget(objet_graphique,"window11");
        gtk_widget_hide(window11);

GtkWidget *window15;
window15 = create_window15();
 gtk_widget_show(window15);
	GtkWidget *label105;

struct personnel p;
	char fichier[] = "personnels.txt";
	
	char tmp[10000]="";
	char Buf[1000]="";
	char Buf0[100]= " ID ";
	char Buf1[100]= " nom ";
	char Buf2[100]= " prenom ";
	char Buf3[100]= " age ";
	char Buf4[100]= " profession ";
	char Buf5[100]= " sexe ";
	char Buf6[100]= " pays ";
	char Buf7[100]= " Nationnalitée ";
	char Buf8[100]= " adresse ";
	char Buf9[100]= " Type du sang ";
	char Buf10[100]= " Telephone ";
FILE*f;

f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, " %d %s %s %d %s %s %s %s %s %s %d \n", &p.iden,p.nom, p.prenom,&p.age,p.profession, p.sexe,p.pays,p.nationnalite,p.adresse,p.tsang,&p.tel) != EOF )
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.profession, Buf5, p.sexe, Buf6,p.pays, Buf7,p.nationnalite, Buf8,p.adresse, Buf9,p.tsang, Buf10,p.tel  );
 strcat(tmp,Buf);
strcat(tmp,"\n\n");
 }
  	
label105= lookup_widget(GTK_WIDGET(window15), "label105");
   gtk_label_set_text(GTK_LABEL(label105),tmp);
  }else {label105= lookup_widget(GTK_WIDGET(window15), "label105");
   gtk_label_set_text(GTK_LABEL(label105),"clinique vide");}
  
fclose(f); 

}


void
on_button32_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window9;
window9 = create_window9();
    gtk_widget_show(window9);

}



void
on_button38_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{

	GtkWidget *window16;
	GtkWidget * label83;

char buf0[10];
char buf1[10];
char tmp[500];       
char res[100];
struct event bilan[200];
int i=0,j=0;
char compare[40]="E01C01S01L01C02V01I01D01B01M01";
char vide[0]="";
analyser_fichier(bilan,&i);
for(j=0;j<i;j++)
{   if ((bilan[j].id / 10000) ==1 )
    {if((strcmp(bilan[j].passage,compare))!=0)
    	{

        strcpy(res,"il'y a des infraction/ consulter alerte.txt");
    	FILE *f;
    	f=fopen("alerte.txt","a");
    	if(f==NULL)
    	{
    	label83= lookup_widget(objet_graphique, "label83");
    	strcpy(res,"erreur");}
    	else {fprintf(f,"%d \n",bilan[j].id);
sprintf(buf0,"%d\n",bilan[j].id);}
strcat(tmp,buf0);
strcat(tmp,"\n\n");    	
	fclose(f);

    	}
    }
    else if  ((bilan[j].id / 10000) ==2 )
    {	if((strcmp(bilan[j].passage,vide))!=0)
    	{

	label83= lookup_widget(objet_graphique, "label83");     
	strcpy(res,"il'y a des infraction/ consulter alerte.txt");
    	FILE *f;
    	f=fopen("alerte.txt","a");
    	if(f==NULL)
    	
    	{
	label83= lookup_widget(objet_graphique, "label83");    	
	strcpy(res,"erreur");}
    	else {fprintf(f," %d \n",bilan[j].id);
sprintf(buf1,"%d\n",bilan[j].id);}
strcat(tmp,buf1);
strcat(tmp,"\n\n");
    	fclose(f);
    	}
    }
    /*else {label83= lookup_widget(objet_graphique, "label83");  
	  strcpy(res,"Pas d'infractions dans le parcours");
	gtk_label_set_text(GTK_LABEL(label83),res);
    }*/
    
    
}//window16 = create_window16();
    //gtk_widget_show(window16);
	gtk_label_set_text(GTK_LABEL(label83),tmp);
//afficher(bilan);
}


void
on_button39_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window9;
window9 = create_window9();
    gtk_widget_show(window9);
GtkWidget *window15;
window15 = create_window15();
    gtk_widget_show(window15);
}


void
on_button40_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window2;
window2 = create_window2();
    gtk_widget_show(window2);
}


void
on_button18_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{int test;
struct patient p;
char fichier[] = "patients.txt";
	GtkWidget *window8;
       GtkWidget *label86;
         char tmp[10000]="";
         char tmp2[10000]="";
	char Buf[1000]="";
	char Buf0[100]= " ID ";
	char Buf1[100]= " nom ";
	char Buf2[100]= " prenom ";
	char Buf3[100]= " age ";
	char Buf4[100]= " observation ";
	char Buf5[100]= " sexe ";
	char Buf6[100]= " adresse ";
	char Buf7[100]= " Type du sang ";
	char Buf8[100]= " pays ";
	char Buf9[100]= " Nationnalitée ";
	char Buf10[100]= " Telephone ";
	char Buf11[100]= " Numero accompagnant ";
	char Buf12[50];
	FILE*f;

f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, "%d %s %s %d %s %s %s %s %s %s %d %d ", &p.iden,p.nom, p.prenom,&p.age,p.observation, p.sexe,p.adresse,p.tsang,p.pays,p.nationnalite,&p.tel,&p.numacc) != EOF )
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.observation, Buf5, p.sexe, Buf6,p.adresse, Buf7,p.tsang, Buf8,p.pays, Buf9,p.nationnalite, Buf10,p.tel,Buf11,p.numacc  );}
 strcat(tmp,Buf);
strcat(tmp,"\n");
 
  	
label86= lookup_widget(GTK_WIDGET(window8), "label86");
   gtk_label_set_text(GTK_LABEL(label86),tmp);
  }else {label86= lookup_widget(GTK_WIDGET(window8), "label86");
   gtk_label_set_text(GTK_LABEL(label86),"clinique vide");}
  
fclose(f); 
int iden;
GtkWidget *entry70;

entry70 = lookup_widget(objet_graphique, "entry70");
iden=atoi(gtk_entry_get_text(GTK_ENTRY(entry70)));
test=chercherpatient(fichier,iden);
if (test=1)
{supprimer_patient(fichier,iden);
f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, "%d %s %s %d %s %s %s %s %s %s %d %d ", &p.iden,p.nom, p.prenom,&p.age,p.observation, p.sexe,p.adresse,p.tsang,p.pays,p.nationnalite,&p.tel,&p.numacc) != EOF )
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.observation, Buf5, p.sexe, Buf6,p.adresse, Buf7,p.tsang, Buf8,p.pays, Buf9,p.nationnalite, Buf10,p.tel,Buf11,p.numacc  );
 strcat(tmp2,Buf);}
strcat(tmp2,"\n");
 
  	
label86= lookup_widget(GTK_WIDGET(window8), "label86");
   gtk_label_set_text(GTK_LABEL(label86),tmp2);
  }else {label86= lookup_widget(GTK_WIDGET(window8), "label86");
   gtk_label_set_text(GTK_LABEL(label86),"clinique vide");}
  
fclose(f); 
sprintf(Buf12,"Patient supprimé \n");
label86= lookup_widget(objet_graphique, "label86"); 
gtk_label_set_text(GTK_LABEL(label86), Buf12);}

else {
sprintf(Buf12,"cet identifiant n'existe pas \n");
label86= lookup_widget(objet_graphique, "label86"); 
gtk_label_set_text(GTK_LABEL(label86), Buf12);}




}


void
on_button19_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window3;
window3 = create_window3();
    gtk_widget_show(window3);


}


void
on_button33_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window13;	
        int test;
	struct personnel p;
		struct personnel pa;
	char fichier[]="personnels.txt";
        char tmp[10000]="";
	char Buf[1000]="";
	char Buf0[100]= " ID ";
	char Buf1[100]= " nom ";
	char Buf2[100]= " prenom ";
	char Buf3[100]= " age ";
	char Buf4[100]= " profession ";
	char Buf5[100]= " sexe ";
	char Buf6[100]= " pays ";
	char Buf7[100]= " Nationnalitée ";
	char Buf8[100]= " adresse ";
	char Buf9[100]= " Type du sang ";
	char Buf10[100]= " Telephone ";;	
char Buf12[50]; 	
	GtkWidget *label85; 	
	GtkWidget *label120; 	 	
        GtkWidget *entry71;
	
entry71 = lookup_widget(objet_graphique, "entry71");
pa.iden = atoi(gtk_entry_get_text(GTK_ENTRY(entry71)));
test=chercherpersonnel(fichier,pa.iden);	
if (test==1)
{
window13 = create_window13();
    gtk_widget_show(window13);
	FILE*f;
f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, " %d %s %s %d %s %s %s %s %s %s %d \n", &p.iden,p.nom, p.prenom,&p.age,p.profession, p.sexe,p.pays,p.nationnalite,p.adresse,p.tsang,&p.tel) != EOF )
  {    if (pa.iden==p.iden){
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.profession, Buf5, p.sexe, Buf6,p.pays, Buf7,p.nationnalite, Buf8,p.adresse, Buf9,p.tsang, Buf10,p.tel );}}fclose(f);
label120= lookup_widget(GTK_WIDGET(window13), "label120");
   gtk_label_set_text(GTK_LABEL(label120),Buf);
}} else  
 {
sprintf(Buf12,"Personnel innexistant \n");
label85= lookup_widget(objet_graphique, "label85"); 
gtk_label_set_text(GTK_LABEL(label85), Buf12);}

}


void
on_button34_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window11;
window11 = create_window11();
    gtk_widget_show(window11);


}


void
on_button35_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
int x;
char fichier[]="personnels.txt";
struct personnel p;
struct personnel pa;
     char tmp[10000]="";
	char Buf[1000]="";
	char Buf0[100]= " ID ";
	char Buf1[100]= " nom ";
	char Buf2[100]= " prenom ";
	char Buf3[100]= " age ";
	char Buf4[100]= " profession ";
	char Buf5[100]= " sexe ";
	char Buf6[100]= " pays ";
	char Buf7[100]= " Nationnalitée ";
	char Buf8[100]= " adresse ";
	char Buf9[100]= " Type du sang ";
	char Buf10[100]= " Telephone ";;	
 	GtkWidget *window13;
	GtkWidget *label120; 	
 	GtkWidget *entry72;
	GtkWidget *entry73;
	GtkWidget *entry74;
	GtkWidget *entry75;
	GtkWidget *entry76;
	GtkWidget *entry77;
	GtkWidget *entry85;
	GtkWidget *entry87;
	GtkWidget *entry88;
	GtkWidget *entry89;
	GtkWidget *entry90;
	GtkWidget *entry91;
        entry72 = lookup_widget(objet_graphique, "entry72");
	entry73 = lookup_widget(objet_graphique, "entry73");
	entry74 = lookup_widget(objet_graphique, "entry74");
	entry75 = lookup_widget(objet_graphique, "entry75");
	entry76 = lookup_widget(objet_graphique, "entry76");
	entry77 = lookup_widget(objet_graphique, "entry77");
	entry88 = lookup_widget(objet_graphique, "entry85");
	entry89 = lookup_widget(objet_graphique, "entry88");
	entry90 = lookup_widget(objet_graphique, "entry87");
	entry91 = lookup_widget(objet_graphique, "entry89");
	entry85 = lookup_widget(objet_graphique, "entry90");
	entry87 = lookup_widget(objet_graphique, "entry91");

	pa.iden = atoi(gtk_entry_get_text(GTK_ENTRY(entry87)));
	strcpy(pa.nom, gtk_entry_get_text(GTK_ENTRY(entry72)));
	strcpy(pa.prenom, gtk_entry_get_text(GTK_ENTRY(entry73)));
	strcpy(pa.pays, gtk_entry_get_text(GTK_ENTRY(entry77)));
	strcpy(pa.adresse, gtk_entry_get_text(GTK_ENTRY(entry90)));
	pa.tel=atoi(gtk_entry_get_text(GTK_ENTRY(entry85)));
	strcpy(pa.tsang, gtk_entry_get_text(GTK_ENTRY(entry89)));
	strcpy(pa.sexe, gtk_entry_get_text(GTK_ENTRY(entry88)));
	pa.age=atoi(gtk_entry_get_text(GTK_ENTRY(entry74)));
	pa.tel=atoi(gtk_entry_get_text(GTK_ENTRY(entry91)));
	strcpy(pa.nationnalite,gtk_entry_get_text(GTK_ENTRY(entry76)));
        strcpy(pa.profession,gtk_entry_get_text(GTK_ENTRY(entry75)));
    supprimer_personnel(fichier,pa.iden);
x=sauvegarder_personnel(fichier,pa);
	FILE*f;
f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, " %d %s %s %d %s %s %s %s %s %s %d \n", &p.iden,p.nom, p.prenom,&p.age,p.profession, p.sexe,p.pays,p.nationnalite,p.adresse,p.tsang,&p.tel) != EOF )
  {    if (pa.iden==p.iden){
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s  %s %s %s %s %s %s %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.profession, Buf5, p.sexe, Buf6,p.pays, Buf7,p.nationnalite, Buf8,p.adresse, Buf9,p.tsang, Buf10,p.tel)  ;}}}fclose(f);
label120= lookup_widget(GTK_WIDGET(window13), "label120");
   gtk_label_set_text(GTK_LABEL(label120),Buf);

}


void
on_button100_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window10;
window10 = create_window10();
    gtk_widget_show(window10);

}


void
on_button101_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window3;
window3 = create_window3();
    gtk_widget_show(window3);
}


void
on_button103_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window1;
window1 = create_window1();
    gtk_widget_show(window1);

}


void
on_button102_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window16;
window16 = create_window16();
    gtk_widget_show(window16);

}


void
on_button36_clicked                    (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window12;
window12 = create_window12();
    gtk_widget_show(window12);
}


void
on_button37_clicked                 (GtkWidget *objet_graphique, gpointer user_data)
{GtkWidget *window14;
window14 = create_window14();
    gtk_widget_show(window14);

}


void
on_radiobutton1_clicked               (GtkWidget *objet_graphique, gpointer user_data)
{
sexe=1;
}


void
on_radiobutton2_clicked               (GtkWidget *objet_graphique, gpointer user_data)
{
sexe=2;
}


void
on_radiobutton4_clicked             (GtkWidget *objet_graphique, gpointer user_data)
{
sexe=2;
}


void
on_radiobutton3_clicked               (GtkWidget *objet_graphique, gpointer user_data)
{
sexe=1;
}


void
on_button97_clicked               (GtkWidget *objet_graphique, gpointer user_data)
{
GtkWidget *window10;
window10 = create_window10();
    gtk_widget_show(window10);
}


void
on_button104_clicked                   (GtkWidget *objet_graphique, gpointer user_data)
{	GtkWidget *window5;
window5 = create_window5();
 gtk_widget_show(window5);
	GtkWidget *label110;

struct patient p;
	char fichier[] = "patients.txt";
	
	char tmp[10000]="";
	char Buf[1000]="";
	char Buf0[100]= " ID ";
	char Buf1[100]= " nom ";
	char Buf2[100]= " prenom ";
	char Buf3[100]= " age ";
	char Buf4[100]= " observation ";
	char Buf5[100]= " sexe ";
	char Buf6[100]= " adresse ";
	char Buf7[100]= " Type du sang ";
	char Buf8[100]= " pays ";
	char Buf9[100]= " Nationnalitée ";
	char Buf10[100]= " Telephone ";
	char Buf11[100]= " Numero accompagnant ";
	FILE*f;

f=fopen(fichier,"rb");
if(f!=NULL)
{
   while(fscanf(f, "%d %s %s %d %s %s %s %s %s %s %d %d ", &p.iden,p.nom, p.prenom,&p.age,p.observation, p.sexe,p.adresse,p.tsang,p.pays,p.nationnalite,&p.tel,&p.numacc) != EOF )
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %d %s %s %s %s %s %s %s %s %s %s %s %s %s %d %s %d ", Buf0, p.iden, Buf1,p.nom, Buf2, p.prenom, Buf3, p.age, Buf4,p.observation, Buf5, p.sexe, Buf6,p.adresse, Buf7,p.tsang, Buf8,p.pays, Buf9,p.nationnalite, Buf10,p.tel,Buf11,p.numacc  );}
 strcat(tmp,Buf);
strcat(tmp,"\n");
 
  	
label110= lookup_widget(GTK_WIDGET(window5), "label110");
   gtk_label_set_text(GTK_LABEL(label110),tmp);
  }else {label110= lookup_widget(GTK_WIDGET(window5), "label110");
   gtk_label_set_text(GTK_LABEL(label110),"clinique vide");}
  
fclose(f); 

}


void
on_button105_clicked        (GtkWidget *objet_graphique, gpointer user_data)       
{GtkWidget * window9;
        window9 = lookup_widget(objet_graphique,"window9");
        gtk_widget_hide(window9);
GtkWidget *window3;
window3 = create_window3();
    gtk_widget_show(window3);

}

